package com.example.micro_property_springboot.controller;

import com.example.micro_property_springboot.pojo.DTO.user.PasswordDTO;
import com.example.micro_property_springboot.pojo.DTO.user.PersonalDTO;
import com.example.micro_property_springboot.pojo.DTO.user.UserDTO;
import com.example.micro_property_springboot.pojo.SysUser;
import com.example.micro_property_springboot.pojo.VO.PageResult;
import com.example.micro_property_springboot.pojo.VO.Result;
import com.example.micro_property_springboot.pojo.VO.UserVO;
import com.example.micro_property_springboot.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "与用户相关的接口")
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 登录
     */
    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public Result<UserVO> login(@RequestBody UserDTO user){
        return userService.login(user);
    }

    /**
     * 注册
     */
    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public Result<Void> register(@RequestBody SysUser user){return userService.register(user);}

    /**
     * 修改个人信息
     */
    @PostMapping("/personal")
    @Operation(summary = "修改个人信息")
    public Result<Void> updateUserPersonal(@RequestParam Long Id,@RequestBody @Valid PersonalDTO personalDTO){
        return userService.updateUserPersonal(Id, personalDTO);
    }

    /**
     * 修改密码
     */
    @PostMapping("/password")
    @Operation(summary = "修改密码")
    public Result<Void> updateUserPassword(@RequestParam Long Id,@RequestBody @Valid PasswordDTO passwordDTO) {
        return userService.updateUserPassword(Id, passwordDTO);
    }


    /**
     *管理员审核用户
     */
    @PostMapping("/pass/{id}")
    @Operation(summary = "管理员审核用户")
    public Result<Void> passUser(@PathVariable Long id){return userService.passUser(id);}

    /**
     * 分页查询待审核用户
     */
    @GetMapping("/selectPass")
    @Operation(summary = "分页查询待审核的用户")
    public Result<PageResult<UserVO>> pagePassUser(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize){
        return userService.pagePassUser(pageNum, pageSize);
    }

    /**
     * 分页查询已通过审核的用户
     */
    @GetMapping("/selectPassed")
    @Operation(summary = "分页查询已通过审核的用户")
    public Result<PageResult<UserVO>> pagePassedUser(@RequestParam Integer pageNum,
                                                     @RequestParam Integer pageSize){
        return userService.pagePassedUser(pageNum, pageSize);
    }

    /**
     * 查询所有用户
     */
    @GetMapping("/selectAll")
    @Operation(summary = "分页查询所有用户")
    public Result<PageResult<UserVO>> pageAllUser(@RequestParam Integer pageNum,
                                                 @RequestParam Integer pageSize){
        return userService.pageAllUser(pageNum, pageSize);
    }

    /**
     * 添加用户
     */
    @PostMapping("/add")
    @Operation(summary = "添加用户")
    public Result<Void> addUser(@RequestBody @Valid SysUser user){
        return userService.addUser(user);
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除用户")
    public Result<Void> deleteUser(@PathVariable Long id){
        return userService.deleteUser(id);
    }
}